from PySide6.QtWidgets import QApplication, QMainWindow, QComboBox, QLabel, QVBoxLayout, QHBoxLayout, QGridLayout, QPushButton, QFileDialog, QMessageBox
from PySide6.QtGui import QIcon, QPixmap, QAction
import sys

class MainView(QMainWindow):
    def __init__(self, controller):
        super().__init__()
        self.controller = controller # 初始化时设置为None
        self.initUI()
        
        
    def initUI(self):
        self.setWindowTitle("My Application")
        self.resize(800, 500)
        
        # 创建菜单栏
        menubar = self.menuBar()
        file_menu = menubar.addMenu('文件')
        help_menu = menubar.addMenu('帮助')

        exit_action = QAction('退出', self)
        exit_action.triggered.connect(self.close)
        file_menu.addAction(exit_action)

        about_action = QAction('关于', self)
        about_action.triggered.connect(lambda: self.controller.show_about())
        help_menu.addAction(about_action)

        theme_action = QAction('主题', self)
        theme_action.triggered.connect(lambda: self.controller.change_theme())
        help_menu.addAction(theme_action)

        # 创建主布局
        main_layout = QVBoxLayout()

        # AD组合框
        ad_combobox = QComboBox()
        for i in range(4):
            ad_combobox.addItem(QIcon(f'resources/ad_icon_{i}.png'), f'AD{i+1}')
        main_layout.addWidget(ad_combobox)

        # 功能组合框
        func_grid = QGridLayout()
        db_icon = QPushButton(QIcon('resources/db_icon.png'), '')
        db_label = QLabel('制作数据库')
        code_icon = QPushButton(QIcon('resources/code_icon.png'), '')
        code_label = QLabel('制作编码')
        future_icon = QPushButton(QIcon('resources/future_icon.png'), '')
        future_label = QLabel('待开发功能...')
        
        db_icon.clicked.connect(lambda: self.controller.run_sub_app('generate_database'))
        code_icon.clicked.connect(lambda: self.controller.run_sub_app('MaterialCodeGenerator'))
        future_icon.clicked.connect(self.controller.show_future_feature_message)

        func_grid.addWidget(db_icon, 0, 0)
        func_grid.addWidget(db_label, 1, 0)
        func_grid.addWidget(code_icon, 0, 1)
        func_grid.addWidget(code_label, 1, 1)
        func_grid.addWidget(future_icon, 0, 2)
        func_grid.addWidget(future_label, 1, 2)
        
        main_layout.addLayout(func_grid)
        
        container = QWidget()
        container.setLayout(main_layout)
        self.setCentralWidget(container)
        
    def set_controller(self, controller):
        self.controller = controller # 设置控制器

    # 其他方法...
    
        